<?php
namespace app\api\controller;
use think\Controller;
use think\Session;
use think\Db;
class User extends Controller
{
    public function __construct(){
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:GET, POST, OPTIONS');
        
    }
    //注册
    public function regster(){

        $pwd=$_POST['pwd'];
        $tel=$_POST['tel'];
      


            $data=['user_name'=>$tel,'user_pwd'=>$pwd];
            $res=Db::name('registry')->insert($data);
            if($res){
                $raw_success = array( 'msg' => 'ok');
                return json($raw_success);
            }
            
                
    }
    //登陆
    public function login(){
        
        $name=$_POST['tel'];
        $pwd=$_POST['pwd'];
        $res=Db::name('registry')
        ->where(['user_name'=>$name,'user_pwd'=>$pwd])
        ->find();
        if(count($res)>0){
            $raw_success = array( 'ids' => $res["login_id"]);
            return json($raw_success);
        }
        else {
            $raw_success = array( 'msg' => 'err');
            return json($raw_success);
        }
    }
    
    
    //修改密码
    public function updatapwd(){
        
        $pwd=$_POST['pwd'];
        $logid=$_POST['logid'];
        $res=Db::name('registry')
        ->where('login_id',$logid)
        ->update(['user_pwd' => $pwd]);
        if($res){
            $raw_success = array( 'msg' => 'ok');
            return json($raw_success);
        }
        
        
    }
    //查询tel
    public  function selectname(){
        $id=$_POST['id'];
        $res=Db::name('registry')
        ->where('login_id','=',$id)
        ->find();
        if($res){
            return json($res);
        }
        
    }
    //房屋关注
    public function followhouse(){
        $houseid=$_POST['houseid'];
        $userid=$_POST['userid'];
        $data=['login_id'=>$userid,'house_id'=>$houseid];
        $res=Db::name('user')->insert($data);
        if($res){
            $raw_success = array( 'msg' => 'ok');
            return json($raw_success);
        }
    }
    public  function followhousecrle(){
        $houseid=$_POST['houseid'];
        $res=Db::name("user")
        ->where('house_id','=',$houseid)
        ->delete();
        if($res){
            $raw_success = array( 'msg' => 'ok');
            return json($raw_success);
        }
    }
    
}

